﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SWCad
{
    public partial class Spline : UserControl
    {
        public Spline()
        {
            InitializeComponent();

            cmbMarkerType.Items.Add("Circle");
            cmbMarkerType.Items.Add("Square");
            cmbMarkerType.Items.Add("Diamond");
            cmbMarkerType.Items.Add("Triangle");
            cmbMarkerType.Items.Add("Pentagon");
            cmbMarkerType.Items.Add("Hexagon");
            cmbMarkerType.Items.Add("Star");
            cmbMarkerType.SelectedIndex = 0;

            cmbMarkerSize.Items.Add("8");
            cmbMarkerSize.Items.Add("10");
            cmbMarkerSize.Items.Add("12");
            cmbMarkerSize.Items.Add("14");
            cmbMarkerSize.Items.Add("16");
            cmbMarkerSize.Items.Add("18");
            cmbMarkerSize.Items.Add("20");
            cmbMarkerSize.Items.Add("22");
            cmbMarkerSize.Items.Add("24");
            cmbMarkerSize.Items.Add("26");
            cmbMarkerSize.Items.Add("28");
            cmbMarkerSize.Items.Add("30");
            cmbMarkerSize.SelectedIndex = 0;

            cmbLabelAngle.Items.Add("0");
            cmbLabelAngle.Items.Add("45");
            cmbLabelAngle.Items.Add("90");
            cmbLabelAngle.Items.Add("135");
            cmbLabelAngle.Items.Add("180");
            cmbLabelAngle.Items.Add("225");
            cmbLabelAngle.Items.Add("270");
            cmbLabelAngle.Items.Add("315");
            cmbLabelAngle.SelectedIndex = 1;

            ChartControl.Content.Legend.Visible = true;
            ChartControl.Content.Legend.HorizontalAlignment = XtremeChartControl.ChartLegendAlignment.xtpChartLegendFar;
            ChartControl.Content.EnableMarkup = true;

            AddSeriesCombination();

            ChartControl.Content.Titles.Add("Population by U.S. State");
            ChartControl.Content.Legend.Visible = true;

            ChartControl.Content.Series[3].Style = (XtremeChartControl.ChartSeriesStyle)new XtremeChartControl.ChartSplineSeriesStyle();
            ChartControl.Content.Series[2].Style = (XtremeChartControl.ChartSeriesStyle)new XtremeChartControl.ChartSplineSeriesStyle();
            ChartControl.Content.Series[1].Style = (XtremeChartControl.ChartSeriesStyle)new XtremeChartControl.ChartSplineSeriesStyle();
            ChartControl.Content.Series[0].Style = (XtremeChartControl.ChartSeriesStyle)new XtremeChartControl.ChartSplineSeriesStyle();

            XtremeChartControl.ChartDiagram2D Diagram;
            Diagram = (XtremeChartControl.ChartDiagram2D)ChartControl.Content.Series[0].Diagram;
            Diagram.AxisY.Title.Text = "Population Growth (Millions)";
            Diagram.AxisY.Title.Visible = true;
            Diagram.AxisX.Title.Text = "Decade / Year";
            Diagram.AxisX.Title.Visible = true;
        }

        public void AddSeriesCombination()
        {
            if (ChartControl.Content.Series.Count > 0)
                ChartControl.Content.Series.DeleteAll();

            ChartControl.Content.Legend.Visible = true;
            ChartControl.Content.Legend.HorizontalAlignment = XtremeChartControl.ChartLegendAlignment.xtpChartLegendNearOutside;

            XtremeChartControl.ChartSeries Series;

            Series = ChartControl.Content.Series.Add("New York");

            Series.Points.Add(1900, 7268);
            Series.Points.Add(1950, 14830);
            Series.Points.Add(1990, 17990);
            Series.Points.Add(2000, 18976);
            Series.Points.Add(2008, 20323);

            Series = ChartControl.Content.Series.Add("California");

            Series.Points.Add(1900, 1485);
            Series.Points.Add(1950, 10586);
            Series.Points.Add(1990, 29760);
            Series.Points.Add(2000, 33871);
            Series.Points.Add(2008, 36756);

            Series = ChartControl.Content.Series.Add("Florida");

            Series.Points.Add(1900, 528);
            Series.Points.Add(1950, 2771);
            Series.Points.Add(1990, 12937);
            Series.Points.Add(2000, 15982);
            Series.Points.Add(2008, 18328);

            Series = ChartControl.Content.Series.Add("Texas");

            Series.Points.Add(1900, 3048);
            Series.Points.Add(1950, 7711);
            Series.Points.Add(1990, 14986);
            Series.Points.Add(2000, 20851);
            Series.Points.Add(2008, 24326);
        }

        private void ChartControl_MouseMoveEvent(System.Object eventSender, AxXtremeChartControl._DChartControlEvents_MouseMoveEvent eventArgs)
        {
            XtremeChartControl.ChartElement Element;
            Element = ChartControl.HitTest(eventArgs.x, eventArgs.y);

            XtremeChartControl.ChartSeriesPoint Point;

            Point = (XtremeChartControl.ChartSeriesPoint)Element;

            if (((Point != null)))
            {
                System.Diagnostics.Debug.WriteLine("Point " + Point[0]);
            }
        }


        private void cmbMarkerSize_SelectedIndexChanged(System.Object eventSender, System.EventArgs eventArgs)
        {
            foreach (XtremeChartControl.ChartSeries x in ChartControl.Content.Series)
            {
                if (x.Style is XtremeChartControl.ChartSplineSeriesStyle)
                    ((XtremeChartControl.ChartSplineSeriesStyle)x.Style).Marker.Size = 8 + (cmbMarkerSize.SelectedIndex * 2);
            }
        }

        private void chkShowMarkers_CheckStateChanged(System.Object eventSender, System.EventArgs eventArgs)
        {
            foreach (XtremeChartControl.ChartSeries x in ChartControl.Content.Series)
            {
                if (x.Style is XtremeChartControl.ChartSplineSeriesStyle)
                    ((XtremeChartControl.ChartSplineSeriesStyle)x.Style).Marker.Visible = chkShowMarkers.Checked;
            }
        }

        private void chkShowLabels_CheckStateChanged(System.Object eventSender, System.EventArgs eventArgs)
        {
            foreach (XtremeChartControl.ChartSeries x in ChartControl.Content.Series)
            {
                x.Style.Label.Visible = chkShowLabels.Checked;
            }
        }

        private void cmbLabelAngle_SelectedIndexChanged(System.Object eventSender, System.EventArgs eventArgs)
        {
            foreach (XtremeChartControl.ChartSeries x in ChartControl.Content.Series)
            {
                if (x.Style is XtremeChartControl.ChartSplineSeriesStyle)
                    ((XtremeChartControl.ChartSplineSeriesStyle)x.Style).Label.Angle = cmbLabelAngle.SelectedIndex * 45;
            }
        }

        private void cmbMarkerType_SelectedIndexChanged(System.Object eventSender, System.EventArgs eventArgs)
        {
            foreach (XtremeChartControl.ChartSeries x in ChartControl.Content.Series)
            {
                if (x.Style is XtremeChartControl.ChartSplineSeriesStyle)
                    ((XtremeChartControl.ChartSplineSeriesStyle)x.Style).Marker.Type = (XtremeChartControl.ChartMarkerType)cmbMarkerType.SelectedIndex;
            }
        }

        private void Spline_Resize(System.Object eventSender, System.EventArgs eventArgs)
        {
            lblTitle.Width = ClientRectangle.Width - 2 * gbOptions.Left;
            gbOptions.Width = ClientRectangle.Width - 2 * gbOptions.Left;
            ChartControl.SetBounds(ChartControl.Left, ChartControl.Top, ClientRectangle.Width - 2 * ChartControl.Left, ClientRectangle.Height - ChartControl.Top - 8);
        }
    }
}
